<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <title>SuperScope | 忘记密码</title>
  <!-- 告诉浏览器屏幕自适应 -->
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <!-- Font Awesome -->
  <link rel="stylesheet" href="../../static/plugins/fontawesome-free/css/all.min.css">
  <!-- Ionicons -->
  <link rel="stylesheet" href="https://cdn.bootcss.com/ionicons/2.0.1/css/ionicons.min.css">
  <!-- icheck bootstrap -->
  <link rel="stylesheet" href="../../static/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
  <!-- 主题样式 -->
  <link rel="stylesheet" href="../../static/dist/css/adminlte.min.css">
  <!-- 离线 Google 字体: Source Sans Pro -->
  <link href="../../static/dist/css/google.css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">

    <link rel="stylesheet" href="../../static/plugins/toastr/toastr.min.css">
</head>
<body class="hold-transition login-page">
<div class="login-box">
  <div class="login-logo">
    <a href="#"><b>Super</b>Scope</a>
  </div>
  <!-- /.login-logo -->
  <div class="card">
    <div class="card-body login-card-body">
      <p class="login-box-msg">忘记了密码？在这里轻松找回。</p>
        <div class="input-group mb-3">
          <input type="text" name="userid" id="userid" class="form-control" placeholder="学号">
          <div class="input-group-append">
            <div class="input-group-text">
              <span class="fas fa-envelope"></span>
            </div>
          </div>
        </div>
        <div class="row">
          <div class="col-12">
            <button type="button" id="forgetPassword" class="btn btn-primary btn-block">找回密码</button>
          </div>
          <!-- /.col -->
        </div>
      <p class="mt-3 mb-1">
        <a href="{{ url_for('login') }}">登录</a>
      </p>
      <p class="mb-0">
        <a href="{{ url_for('register') }}" class="text-center">注册新会员</a>
      </p>
    </div>
    <!-- /.login-card-body -->
  </div>
</div>
<!-- /.login-box -->

<!-- jQuery -->
<script src="../../static/plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../../static/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- AdminLTE App -->
<script src="../../static/dist/js/adminlte.min.js"></script>
<script src="../../static/plugins/toastr/toastr.min.js"></script>

<script type = "text/javascript" >
    $('#forgetPassword').on('click',
  function() {
        var userid = $('#userid').val();

        var data = {
            data:JSON.stringify({
                'userid':userid,
            }),
        }

        //检测部分
        if(userid === ""){
            toastr.error('不能有数据为空');
            return ;
        }

        if(userid.length !== 10){
            toastr.error('请输入正确的学号');
            return ;
        }

        //提交
        $.ajax({
            type:"POST",
            dataType:"json",
            url:"/login/forgotPassword",
            data: data,
            success :function (result){
                console.log(result);
                if(result !== "没有此学号"){
                    toastr.success("已发送验证码!电话为：" + result['phone']);
                    setTimeout(function (){window.location.href = '/login/recoverPassword?' + result['pin'] + '?' + userid},2000);
                }
                else
                    toastr.error(result);
            },
            error:function (result){
                console.log(result);
                toastr.error('未知错误!请联系管理员');
            }
        });
  })
</script>

</body>
</html>
